﻿using Memorandum.Views;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Memorandum.Service
{
   public class MessageManager
    {
        private MessageManager()
        {

        }
       
        private static MessageManager instance;

        public static MessageManager Instance
        {
            get 
            {
                if(instance==null)
                {
                    instance=new MessageManager();
                }
                return instance; 
            }     
        }
        private List<ToastMessage> lst = new List<ToastMessage>();
        public void show(string title, string content,DateTime dt)
        {
            ToastMessage msg = new ToastMessage();
            msg.Title = title;
            msg.Content = content;
            msg.Datetime = dt;
            var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
            msg.Left = desktopWorkingArea.Right - msg.Width;
            msg.Top = desktopWorkingArea.Bottom - msg.Height*(lst.Count+1);


            msg.Show();
            msg.Closed += Msg_Closed;
            lst.Add(msg);
        }

        private void Msg_Closed(object sender, EventArgs e)
        {
            lst.Remove((ToastMessage)sender);
            reLocation();

        }
        private void reLocation()
        {
           for(int i=0;i<lst.Count;i++)
            {
                ToastMessage msg = lst[i];
                var desktopWorkingArea = System.Windows.SystemParameters.WorkArea;
                msg.Left = desktopWorkingArea.Right - msg.Width;
                msg.Top = desktopWorkingArea.Bottom - msg.Height * (i + 1);
            }
        }
    }
}
